package com.lining.orangeservice.entity.po;

import lombok.Data;

import java.math.BigDecimal;

@Data
// 订单项
public class OrderItem {
    private Long itemId;
    private Long orderId;
    private Long productId;
    private String productName;
    private BigDecimal unitPrice;
    private Integer quantity;
    private String productImage;
    
    // 计算小计
    public BigDecimal getSubTotal() {
        return unitPrice.multiply(new BigDecimal(quantity));
    }
    
    // 业务方法
    public void increaseQuantity(int amount) {
        if (amount <= 0) {
            throw new IllegalArgumentException("增加数量必须大于0");
        }
        this.quantity += amount;
    }
    
    public void decreaseQuantity(int amount) {
        if (amount <= 0) {
            throw new IllegalArgumentException("减少数量必须大于0");
        }
        if (this.quantity - amount < 1) {
            throw new IllegalStateException("商品数量不能少于1");
        }
        this.quantity -= amount;
    }
    
    // getters and setters...
}